package com.lmx.persistence.service;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Service;

import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.tmodel.Customer;
import com.lmx.repoDomain.tmodel.Employee;
import com.lmx.repoDomain.tmodel.NursingPlanExecute;

/**
 * 护理方案执行service实现
 *
 * @author ytche
 * @date 2017年8月23日
 *
 */
@Service
public class NursingPlanExecuteServiceImpl extends
		BaseCrudServiceImpl<NursingPlanExecute> implements
		NursingPlanExecuteService {
	@Override
	public List<NursingPlanExecute> findExeOfCustomers(Long tenantId,
			List<Customer> customers, Integer startTime, Integer endTime,
			Employee employee) {
		StringBuilder queryDetailExe = new StringBuilder(
				"select c from NursingPlanExecute c "
						+ " where c.delStatus != 1 and c.tenant.id=:tenantId"
						+ " and c.createDateTime >= :startTime and c.createDateTime < :endTime ");
		if (customers != null && customers.size() > 0) {
			queryDetailExe
					.append(" and c.itemProject.project.customer in (:customers) and c.exeStaff.id=:employeeId and c.detail is not null ");
		}
		Query query = this.em.createQuery(queryDetailExe.toString())
				.setParameter("tenantId", tenantId)
				.setParameter("startTime", startTime)
				.setParameter("endTime", endTime)
				.setParameter("employeeId", employee.getId());
		if (customers != null && customers.size() > 0) {
			query.setParameter("customers", customers);
		}
		return query.getResultList();
	}

}
